<?php

namespace App\Livewire;

use App\Models\Post;
use Illuminate\Database\Eloquent\Collection;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Url;
use Livewire\Component;

class Agreement extends Component
{
    #[Url]
    public ?int $post_id = null;

    public function render()
    {
        return view('livewire.agreement');
    }

    #[Computed]
    public function posts(): Collection
    {
        return Post::withoutGlobalScopes()->whereIn('id', [1, 2])->get();
    }

    #[Computed]
    public function current()
    {
        $posts = $this->posts();

        return $posts->first(fn(Post $post) => !$this->post_id || $post->getKey() === $this->post_id);
    }
}
